"""
@Project ：python
@File    ：02-基础时间柱状图.py
@IDE     ：PyCharm
@Author  ：DongCha
@Date    ：2024/4/8 008 16:15
"""

from pyecharts.charts import Bar, Timeline
from pyecharts.options import *
from pyecharts.globals import ThemeType

bar1 = Bar()
bar1.add_xaxis(["a", "b", "c"])
bar1.add_yaxis("GDP", [30, 20, 10], label_opts=LabelOpts(position="right"))
bar1.reversal_axis()

bar2 = Bar()
bar2.add_xaxis(["a", "b", "c"])
bar2.add_yaxis("GDP", [40, 30, 20], label_opts=LabelOpts(position="right"))
bar2.reversal_axis()

bar3 = Bar()
bar3.add_xaxis(["a", "b", "c"])
bar3.add_yaxis("GDP", [50, 40, 30], label_opts=LabelOpts(position="right"))
bar3.reversal_axis()

# 创建时间轴对象
# {"theme": ThemeType.LIGHT} 设置主题
time_line = Timeline({"theme": ThemeType.LIGHT})
# 添加柱状图
time_line.add(bar1, "2020")
time_line.add(bar2, "2021")
time_line.add(bar3, "2022")
# 自动播放
# add_schema 设置模式
time_line.add_schema(
    play_interval=1000,  # 播放时间间隔
    is_timeline_show=True,  # 是否显示时间线
    is_auto_play=True,  # 是否自动播放
    is_loop_play=True  # 是否循环播放
)
# 绘制图表
time_line.render("./bars/bar_time.html")
